package com.wuxu.skin_inner

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import com.wuxu.lib_skin_core.constant.SKIN_INNER_TYPE_BLUE
import com.wuxu.lib_skin_core.constant.SKIN_INNER_TYPE_YELLOW
import com.wuxu.lib_skin_core.res.Observable
import com.wuxu.lib_skin_core.res.ResourceSingleton
import com.wuxu.lib_skin_core.res.SkinManager

class MainActivity : AppCompatActivity(), Observable {
    private val tvBtn by lazy {
        findViewById<TextView>(R.id.tv_btn)
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        SkinManager.registerObservable(this)

        var isBlue = false
        tvBtn.setOnClickListener {
            if (isBlue) {
                SkinManager.loadSkin(this, SKIN_INNER_TYPE_BLUE)
            } else {
                SkinManager.loadSkin(this, SKIN_INNER_TYPE_YELLOW)
            }

            isBlue = !isBlue
        }
    }

    override fun update(data: Any?) {
        tvBtn.setBackgroundColor(ResourceSingleton.getColor(this,R.color.skin))
    }
}